package models.re.simulatedData;



import javax.persistence.Entity;

import play.db.jpa.JPA;

import models.aaa.Asset.Type;
import models.aaa.Node;
import models.re.IItem;

@Entity
public class Item extends Node implements IItem {
	
	private Type type = Type.EMPTY;
	
	private String dataset = null;
	
	private String name = null;
	
	public static Type str2Item(String type) {
		if (type.toLowerCase().indexOf("space") >= 0) {
            return Type.SPACE;
        } else if (type.toLowerCase().indexOf("asset") >= 0) {
            return Type.ASSET;
        } else if (type.toLowerCase().indexOf("actor") >= 0) {
            return Type.ACTOR;
        } else {
            return Type.EMPTY;
        }
	}
	
	Item() {
		
	}
	
	Item(String type, String dataset, String name) {
        this.type=Item.str2Item(type);
        this.dataset=dataset;
        this.name=name;
	}
	
	public static Item get(Long id) {
		return JPA.em().find(Item.class, id);
	}

	/* (non-Javadoc)
	 * @see models.re.simulatedData.IItem#getType()
	 */
	@Override
	public Type getType() {
		return this.type;
	}

	/* (non-Javadoc)
	 * @see models.re.simulatedData.IItem#getDataset()
	 */
	@Override
	public String getDataset() {
		return dataset;
	}

	/* (non-Javadoc)
	 * @see models.re.simulatedData.IItem#getName()
	 */
	@Override
	public String getName() {
		return name;
	}
	
	/* (non-Javadoc)
	 * @see models.re.simulatedData.IItem#getStrId()
	 */
	@Override
	public String getStrId() {
		return Long.toString(super.getId());
	}

}
